home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGBLER / MATHASM.LZH / INT_F.ASM < prev    next >
Assembly Source File  |  1985-12-03  |  2KB  |  51 lines

  1. INT_F    PROC     NEAR
  2. ;***************************************************************
  3. ;                    rounds and converts a floating point number
  4. ;                    to a signed 32-bit integer
  5. ;***************************************************************
  6.          PUSH     SI              ;save index registers
  7.          PUSH     DI   
  8.          CALL     RN_F            ;round to nearest integer
  9.                                   ;rounded result now in DX:AX
  10.          SUB      CX,CX           ;clear CX
  11.          MOV      DI,10000000B    ;isolate sign in DI
  12.          AND      DI,DX
  13.          OR       DL,10000000B    ;restore leading 1
  14. ;
  15.          MOV      CL,DH           ;exponent in CX
  16.          SUB      DH,DH           ;clear DH
  17.          SUB      CX,128          ;remove exponent bias
  18. ;                            exponent in range 0 < exponent <=31?
  19.          JLE      INT7            ;return 0 result with underflow
  20.          CMP      CX,32           ;must be less than 32
  21.          JGE      INT8            ;return overflow
  22. ;                            shift left or right
  23.          SUB      CX,24
  24.          JE       INT4            ;if exponent = 24, no shift
  25.          JL       INT2            ;if exponent < 24, shift right
  26. INT1:    SHL      AX,1            ;shift left
  27.          RCL      DX,1
  28.          LOOP     INT1
  29.          JMP      INT4
  30. ;                            shift right
  31. INT2:    NEG      CX
  32. INT3:    SHR      DX,1
  33.          RCR      AX,1
  34.          LOOP     INT3
  35. ;
  36. INT4:    SUB      BX,BX           ;completion status=0  OK
  37. ;                            check sign
  38. INT5:    OR       DI,DI
  39.          JZ       INT6            ;if number was negative
  40.          NOT      DX              ;negate it
  41.          NOT      AX
  42.          ADD      AX,1
  43.          ADC      DX,0
  44. ;
  45. INT6:    JMP      EXIT
  46. INT7:    JMP      UNDER_F
  47. INT8:    MOV      DX,7FFFH        ;return maximum signed integer
  48.          MOV      AX,0FFFFH
  49.          MOV      BX,1            ;completion status=+1
  50.          JMP      INT5            ;check sign
  51. INT_F    ENDP